package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.constant.CustomerModuleType;
import org.jsola.hr.dto.CustomTemplateAddDTO;
import org.jsola.hr.dto.CustomTemplateUpdateDTO;
import org.jsola.hr.entity.CustomTemplateDO;
import org.jsola.hr.query.CustomTemplateQuery;
import org.jsola.hr.service.ICustomTemplateService;
import org.jsola.hr.vo.CustomTemplateVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 自定义模板
 *
 * @author zhr
 */
@Component
public class CustomTemplateTestHelper extends BaseTestHelper {
    
    @Autowired
    private ICustomTemplateService customTemplateService;

    /**
     * 生成add测试数据
     * @return CustomTemplateAddDTO
     */
    public CustomTemplateAddDTO getCustomTemplateAddDTO(){
        CustomTemplateAddDTO customTemplateAddDTO = new CustomTemplateAddDTO();
        customTemplateAddDTO.setIsDefault(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        customTemplateAddDTO.setIsOpen(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        customTemplateAddDTO.setIsIssue(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        customTemplateAddDTO.setSourceId(getRandomValue("varchar",32));
        customTemplateAddDTO.setName(getRandomValue("varchar",50));
        customTemplateAddDTO.setModuleName(getRandomValue("varchar",50));
        customTemplateAddDTO.setModuleCode(CustomerModuleType.ON_JOB.getValue());
        customTemplateAddDTO.setCompanyId(getRandomValue("varchar",32));
        customTemplateAddDTO.setEditBy(getRandomValue("varchar",32));
        customTemplateAddDTO.setType(SafeKit.getInteger(getRandomValue("int",1)));
        return customTemplateAddDTO;
    }


    /**
     * 生成update测试数据
     * @return CustomTemplateUpdateDTO
     */
    public CustomTemplateUpdateDTO getCustomTemplateUpdateDTO(CustomTemplateVO customTemplateVO){
        return customTemplateService.selectDOById(customTemplateVO.getId()).to(CustomTemplateUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return CustomTemplateQuery
     */
    public CustomTemplateQuery getCustomTemplateQuery() {
        CustomTemplateQuery customTemplateQuery = new CustomTemplateQuery();
        List<CustomTemplateDO> customTemplateDOList = customTemplateService.list(new CustomTemplateDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(customTemplateDOList)) {
            CustomTemplateDO customTemplateDO = customTemplateDOList.get(0);
            customTemplateQuery = customTemplateDO.to(CustomTemplateQuery.class);
        }
        return customTemplateQuery;
    }

    /**
     * 保存示例
     * @return CustomTemplateVO
     */
    public CustomTemplateVO saveCustomTemplateExample(){
        CustomTemplateAddDTO addDTO = this.getCustomTemplateAddDTO();
        CustomTemplateVO customTemplateVO = customTemplateService.save(addDTO,buildTokenUser());
        return customTemplateVO;
    }


}

